package com.xhji.spider.entity;

import com.xhji.web.mvc.validation.rules.Create;
import com.xhji.web.mvc.validation.rules.Update;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "page_detail_rule")
public class PageDetailRule {
    /**
     * 主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = Create.class)
    @NotNull(groups = Update.class, message = "id不能为空")
    private Integer id;

    /**
     * 网站根域名
     */
    @NotBlank(groups = {Create.class,Update.class}, message = "请输入网站根域名")
    private String domain;

    /**
     * 标题获取规则
     */
    @Column(name = "title_regex")
    private String titleRegex;

    /**
     * 作者获取规则
     */
    @Column(name = "author_regex")
    private String authorRegex;

    /**
     * 创建日期获取规则
     */
    @Column(name = "date_regex")
    private String dateRegex;

    /**
     * 内容获取规则
     */
    @Column(name = "content_regex")
    private String contentRegex;

    /**
     * 描述获取规则
     */
    @Column(name = "description_regex")
    private String descriptionRegex;

    /**
     * 文章分类获取规则
     */
    @Column(name = "catalog_regex")
    private String catalogRegex;

    /**
     * 标签获取规则
     */
    @Column(name = "tag_regex")
    private String tagRegex;

    /**
     * 图片获取规则
     */
    @Column(name = "image_regex")
    private String imageRegex;

    /**
     * 每个页面等待时间
     */
    @Column(name = "sleep_time")
//    @NotNull(groups = {Create.class,Update.class}, message = "请输入超时时间")
    private Integer sleepTime;

    /**
     * 抓取失败重试次数
     */
    @Column(name = "retry_times")
//    @NotNull(groups = {Create.class,Update.class}, message = "请输入重试次数")
    private Integer retryTimes;

    /**
     * 线程个数
     */
    @Column(name = "thread_count")
    @NotNull(groups = {Create.class,Update.class}, message = "请输入线程个数")
    private Integer threadCount;

    /**
     * 退出方式{DURATION:爬虫持续的时间,URL_COUNT:抓取到的url数量}
     */
    @Column(name = "exit_way")
    @NotBlank(groups = {Create.class,Update.class}, message = "请选择退出方式")
    private String exitWay;

    /**
     * 对应退出方式，当exitWay = URL_COUNT时，该值表示url数量，当exitWay = DURATION时，该值表示爬虫持续的时间
     */
    @Column(name = "exit_way_count")
    private Integer exitWayCount;

    /**
     * 请求的User Agent
     */
    @Column(name = "user_agent")
    @NotBlank(groups = {Create.class,Update.class}, message = "请选择UA")
    private String userAgent;

    /**
     * 需要的cookie
     */
    private String cookies;

    /**
     * 请求头
     */
    private String header;

    /**
     * 目标url规则
     */
    @Column(name = "target_url_regex")
    @NotBlank(groups = {Create.class,Update.class}, message = "请输入目标url规则")
    private String targetUrlRegex;

    /**
     * 辅助查询目标url规则(列表页规则)
     */
    @Column(name = "help_url_regex")
    private String helpUrlRegex;

    /**
     * 辅助页中目标url所在区域规则
     */
    @Column(name = "target_url_module_regex")
    private String targetUrlModuleRegex;


    /**
     * 起始页
     */
    @Column(name = "start_url")
    @NotBlank(groups = {Create.class,Update.class}, message = "请输入起始页")
    private String startUrl;
}